const { Router } = require('express')
const router = new Router()

// 引入时间格式化模块
const momentTimeX = require('../../utils/formatTime/momentTime')
// 引入轮播图模型
const RotationModel = require('../../model/rotation')
// 引入

router.get('/showRotation',function (request, response) {
    const time = new Date()
    let launchStartTime = `${time.getHours()>10?time.getHours():'0'+time.getHours()}:${time.getMinutes()>10?time.getMinutes():'0'+time.getMinutes()}`
    const startTime = momentTimeX(launchStartTime)
    // let endTime = momentTimeX('23:59')

    RotationModel.find({
        launchStartTimeX:{
            $lte: startTime
        },
        isShow: 0,
        chargeNum:{
            $gt: 0
        }
    },{
        goodsId: 1,
        rotationPic: 1,
        launchStartTime: 1,
        launchEndTime: 1,
        isShow: 1,
        bidPrice: 1,
        _id: 0
    }).sort({bidPrice: -1}).limit(10).exec(function (err,doc) {
        const data = {
            code: '200',
            data: 'error',
            msg: '轮播图调用结果失败'
        }
        if (err) return response.json(data)

        data.data = doc
        data.msg = '调用轮播图成功'

        return response.json(data)
    })
})

module.exports = router
